package com.cuitrip.business.bill;

import android.app.Activity;
import android.content.Intent;
import android.graphics.Bitmap;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.cuitrip.business.notice.model.FeeDescription;
import com.cuitrip.business.pay.PayOrderFeeDescriptionFragment;
import com.cuitrip.service.R;
import com.lab.app.BaseActivity;
import com.lab.image.process.MakeImageUtil;

import java.util.ArrayList;


/**
 * Created by MiJack on 2015/11/2.
 */
public class ExplainActivity extends BaseActivity {
    public static final String KEY_CODE = "KEY_CODE";
    public static final String BACKGROUND_CODE = "BACKGROUND_CODE";
    public static final int SHOW_INFO_ABOUT_BALANCE = 1;
    public static final int SHOW_INFO_ABOUT_RATING  = 2;
    public static final int SHOW_INFO_ABOUT_FEE_DESCRIPTION=3;

    TextView titleView;
    TextView closeView;
    ImageView mBackgroundImageView;
    private ArrayList<FeeDescription> notice;

    public static void startActivityBy(Activity activity, int code) {
        Intent intent = new Intent(activity, ExplainActivity.class);
        intent.putExtra(KEY_CODE, code);
        Bitmap bitmap = MakeImageUtil.takeScreenShot(activity);
        if (bitmap != null) {
            intent.putExtra(BACKGROUND_CODE, bitmap);
        }
        activity.startActivity(intent);
    }

    public static void startActivityBy(Activity activity, Intent intent) {
        Bitmap bitmap = MakeImageUtil.takeScreenShot(activity);
        if (bitmap != null) {
            intent.putExtra(BACKGROUND_CODE, bitmap);
        }
        activity.startActivity(intent);
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_explain);
        overridePendingTransition(R.anim.context_menu_enter,R.anim.context_menu_exit);
        titleView = (TextView) findViewById(R.id.title);
        closeView = (TextView) findViewById(R.id.close);
        mBackgroundImageView = (ImageView) findViewById(R.id.background);
        closeView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                ExplainActivity.this.finish();
                overridePendingTransition(R.anim.context_menu_enter, R.anim.context_menu_exit);
            }
        });
        if (getIntent()!=null){
            notice = getIntent().getParcelableArrayListExtra("notice");
        }
        if (getIntent().hasExtra(BACKGROUND_CODE)){
            Bitmap bitmap = getIntent().getParcelableExtra(BACKGROUND_CODE);
            mBackgroundImageView.setImageBitmap(bitmap);
        }

        switch (getIntent().getIntExtra(KEY_CODE, -1)) {
            case SHOW_INFO_ABOUT_BALANCE:
                showTitle(getString(R.string.transaction_attribute_balance));
                getSupportFragmentManager().beginTransaction().replace(R.id.frameLayout, new BalanceInfoFragment()).commit();
                break;
            case SHOW_INFO_ABOUT_RATING:
                titleView.setVisibility(View.GONE);
                getSupportFragmentManager().beginTransaction().replace(R.id.frameLayout, new RatingTodayFragment()).commit();
                break;

            case  SHOW_INFO_ABOUT_FEE_DESCRIPTION:
                getSupportFragmentManager().beginTransaction().replace(R.id.frameLayout,PayOrderFeeDescriptionFragment.newInstance(notice)).commit();
                break;


        }
    }

    public void showTitle(String title) {
        titleView.setVisibility(View.VISIBLE);
        titleView.setText(title);
    }

    public static class BalanceInfoFragment extends Fragment {
        @Override
        public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
            return inflater.inflate(R.layout.fragment_balance_info, container, false);
        }
    }
}
